package com.yuwei.user.entity

import android.Manifest
import android.R.attr
import android.content.Context
import android.content.pm.PackageManager
import androidx.core.content.ContextCompat
import java.util.regex.Pattern


open class GetPermissions {

    companion object{
        // 检查联系人/通讯录权限
        fun hasContactsPermission(context: Context): Boolean {
            return ContextCompat.checkSelfPermission(
                context,
                Manifest.permission.READ_CONTACTS
            ) == PackageManager.PERMISSION_GRANTED
        }
        // 正则匹配手机号
        fun regexPhoneNumber(phoneNumber:String):Boolean{
            val regex="^1[3-9]\\d{9}$"
            val pattern = Pattern.compile(regex)
            return pattern.matcher(phoneNumber).matches()
        }
        // 隐藏手机号
        fun desensitizePhoneNumber(phoneNumber: String):String{
            return if (phoneNumber.length == 11) {
                val prefix = phoneNumber.substring(0, 3)
                val suffix = phoneNumber.substring(phoneNumber.length - 4)
                "$prefix****$suffix"
            } else {
                "无效手机号"
            }
        }
    }

}
